<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '../../../static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	import urlUtil from "@/static/js/urlUtil.js"
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				userListCache:"mar-xs-tsalesContractReview-title4-userlist-cache"
			})
		},
		methods:{
			initPosList(userId){
				let _that = this
				_that.om.request(
					"orgInstPosUserOfficial/getPosList",
					{
						"user.id":userId
					},
					"post"
				).then(res=>{
					_that.$refs.autoform.changeEditor("title4","posId","data",configSelectData(res,"id","posname"))
				})
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.userListCache,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.userId = d.id
							formdata.userName = d.username
							_that.initPosList(d.id)	 
							uni.removeStorage({
								key:_that.userListCache
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
								changeEditor("title4","userId",{
									link:'../../public/pageSearch/pageSearch',
									"linkParam":{
										other:JSON.stringify({}),
										namefield:urlUtil.userPageUrl().namefield,
										placeholder:urlUtil.userPageUrl().prompt,
										url:urlUtil.userPageUrl().url,
										initload:true,
										cachename:_that.userListCache,
										searchfield:'q'
									}
								},null,_that.autoformdata)
							}
						}
					})
				}
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                  
